# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(MCFeature)

set(CMAKE_BUILD_RPATH 
   "./"
   )
#--------------------------------------------------------------------------------
# Find ROOT 
#
find_package(ROOT REQUIRED)

# ROOT version 6 required
if(ROOT_FOUND)
  STRING(REGEX MATCH "6.*" VERSION6MATCH ${ROOT_VERSION})
  if(NOT VERSION6MATCH)
    message(FATAL_ERROR "CXPD requires ROOT 6")
  endif()
endif()
#  message(FATAL_ERROR "ROOT NOT FOUND")
  
#--------------------------------------------------------------------------------
# Find OpenCV 
#
find_package(OpenCV)

#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include 
                    ${OpenCV_INCLUDE_DIRS}
                    ${ROOT_INCLUDE_DIRS})

#message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")
#message("OpenCV_INCLUDE_DIR: ${OpenCV_INCLUDE_DIRS}")
#message("ROOT_INCLUDE_DIR: ${ROOT_INCLUDE_DIRS}")

file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cpp)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.h)

#----------------------------------------------------------------------------
# Build SimEvent
#
ROOT_GENERATE_DICTIONARY(SimEvent ${PROJECT_SOURCE_DIR}/include/SimEvent.h LINKDEF ${PROJECT_SOURCE_DIR}/include/Linkdef.h)
add_library(SimEventDict SHARED SimEvent.cxx)
set(libsuffix .so)
set(ROOT_LIBRARY_PROPERTIES ${ROOT_LIBRARY_PROPERTIES} SUFFIX ${libsuffix})
set_target_properties(SimEventDict PROPERTIES ${ROOT_LIBRARY_PROPERTIES})
target_link_libraries(SimEventDict ${ROOT_LIBRARIES})

add_executable(MCFeature main.cpp ${sources} ${headers})

target_link_libraries(MCFeature SimEventDict ${OpenCV_LIBRARIES} -lgfortran ${ROOT_LIBRARIES})
